package cn.wizzer.app.user.modules.service.impl;
import cn.wizzer.app.user.modules.models.UserAccount;
import cn.wizzer.app.user.modules.services.account.UserAccountService;
import cn.wizzer.framework.base.service.BaseServiceImpl;
import com.alibaba.dubbo.config.annotation.Service;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.IocBean;

import java.math.BigDecimal;

@IocBean(args = {"refer:dao"})
@Service(interfaceClass= UserAccountService.class)
public class UserAccountServiceImpl extends BaseServiceImpl<UserAccount> implements UserAccountService {


    public UserAccountServiceImpl(Dao dao) {
        super(dao);
    }


    @Override
    public UserAccount selectByUserId(String userId) {
        UserAccount userAccount = this.fetch(Cnd.where("user_id", "=", userId));
        if (null == userAccount){
            userAccount = new UserAccount();
            userAccount.setTotal(BigDecimal.ZERO);
            userAccount.setFrozen(BigDecimal.ZERO);
            userAccount.setBalance(BigDecimal.ZERO);
            userAccount.setCtAt(System.currentTimeMillis());
            userAccount.setUserId(userId);
            this.insert(userAccount);
        }
        return userAccount;
    }
}
